<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/14
 * Time: 14:04
 */
session_start();
$num=$_POST['num'];
include '../classes/conn.php';
if(isset($_SESSION['admin_num'])) {
    $query1="delete from teacher where num='{$num}'";
    $query2="delete from class where teacher='{$num}'";
    $query3="delete from section where teacher='{$num}'";
    $query4="delete from student where teacher='{$num}'";
    $query5="delete from subsection where teacher='{$num}'";
    mysql_query($query1);
    mysql_query($query2);
    mysql_query($query3);
    mysql_query($query4);
    mysql_query($query5);
    if(deldir("../Files/".$num)){
        echo '1';
    }
    else echo '1';
}
else echo 'no_login';


function deldir($dir){
    $dh=opendir($dir);
    while($file=readdir($dh)){
        if($file!="." && $file!=".."){//判断是不是本目录和上级目录
            if(!is_dir($dir."/".$file)){
                unlink($dir."/".$file);
            }else{
                //递归
                deldir($dir."/".$file);
            }
        }
    }
    closedir($dh);
    if(rmdir($dir)){
        return true;
    }else{
        return false;
    }
}
